package com.example.composeapplication

import android.os.Bundle
import android.os.Message
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.magnifier
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Button
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.example.composeapplication.ui.theme.MyApplicationc4Theme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationc4Theme {
                // A surface container using the 'background' color from the theme
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background

                ) {
                    Column {
//                        Greeting("Android")
//                        Greetingtext(name = "你好世界")
                        PreviewMessage()
                    }


                }
            }
        }
    }
}

data class Message1(val author:String, val body: String)
@Composable
fun idcard(msg: Message1){
    Row(modifier = Modifier.padding(all = 8.dp)) {
       Image(painter = painterResource(id = R.drawable.head), contentDescription = "this is a id card",
          modifier = Modifier
              .size(40.dp)
              .clip(CircleShape)//设置图片为圆角
              .border(1.5.dp, MaterialTheme.colorScheme.secondary, CircleShape)
       )
    Spacer(modifier = Modifier.width(8.dp))
    
    Column {
        Text(
            text = msg.author,
            color = MaterialTheme.colorScheme.onSurface,
            style = MaterialTheme.typography.titleSmall)

        Spacer(modifier = Modifier.height(4.dp))

        Surface(shape = MaterialTheme.shapes.medium, shadowElevation = 1.dp) {
            Text(
                text = msg.body,
                modifier = Modifier.padding(all = 4.dp),
                style = MaterialTheme.typography.bodyMedium)
        }
    }    
    }
}
@Preview(showBackground = true)
@Composable
fun PreviewMessage(){
    Surface {
        idcard(msg = Message1("赵云","this is a test"))
    }

}





